package cc.owoo.godpen.network.throughput;

import java.io.InputStream;
import java.io.OutputStream;

/**
 * 吞吐量（总流量）
 * Created by nimensei
 * 2022-03-31 上午 01:58
 **/
public class OverallThroughput implements Throughput {
    private final ReadThroughput readThroughput = new ReadThroughput();// 接收流量计数器
    private final WriteThroughput writeThroughput = new WriteThroughput();// 发送流量计数器

    /**
     * 创建并监听输入流
     *
     * @param input 输入流
     * @return 监听中的输入流
     */
    public InputStream count(InputStream input) {
        return readThroughput.count(input);
    }

    /**
     * 创建并监听输出流
     *
     * @param output 输出流
     * @return 监听中的输出流
     */
    public OutputStream count(OutputStream output) {
        return writeThroughput.count(output);
    }

    @Override
    public long size() {
        return readThroughput.size() + writeThroughput.size();
    }

    /**
     * 获取接收流量
     *
     * @return 接收流量
     */
    public long readSize() {
        return readThroughput.size();
    }

    /**
     * 获取发送流量
     *
     * @return 发送流量
     */
    public long writeSize() {
        return writeThroughput.size();
    }
}
